home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
gnat1792.zip
/
gnat179b
/
t-adainc
/
s-pthrea.adb
< prev
next >
Wrap
Text File
|
1994-05-19
|
25KB
|
807 lines
------------------------------------------------------------------------------
-- --
-- GNU ADA RUNTIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . P T H R E A D S --
-- --
-- B o d y --
-- --
-- $Revision: 1.6 $ --
-- --
-- Copyright (c) 1991,1992,1993, FSU, All Rights Reserved --
-- --
-- GNARL is free software; you can redistribute it and/or modify it under --
-- terms of the GNU Library General Public License as published by the --
-- Free Software Foundation; either version 2, or (at your option) any --
-- later version. GNARL is distributed in the hope that it will be use- --
-- ful, but but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Gen- --
-- eral Library Public License for more details. You should have received --
-- a copy of the GNU Library General Public License along with GNARL; see --
-- file COPYING. If not, write to the Free Software Foundation, 675 Mass --
-- Ave, Cambridge, MA 02139, USA. --
-- --
------------------------------------------------------------------------------
with Unchecked_Conversion;
package body System.Pthreads is
-----------------------------------------------------------------------
-- These unchecked conversion functions are used to convert a variable
-- to an access value referencing that variable. The expression
-- Address_to_Pointer(X'Address) evaluates to an access value referencing
-- X; if X is of type T, this expression returns a value of type
-- access T. This is necessary to allow structures to be passed to
-- C functions, since some compiler interfaces to C only allows scalers,
-- access values, and values of type System.Address as actual parameters.
-----------------------------------------------------------------------
-- ??? it would be better to use the routines in System.Storage_Elements
-- ??? for conversion between pointers and access values. In any case
-- ??? I don't see the point of these conversions at all, why not pass
-- ??? Address values directly to the C routines (I = RBKD)
function Address_to_Pointer is new
Unchecked_Conversion (System.Address, POSIX_RTE.sigset_t_ptr);
type pthread_t_ptr is access pthread_t;
function Address_to_Pointer is new
Unchecked_Conversion (System.Address, pthread_t_ptr);
type pthread_attr_t_ptr is access pthread_attr_t;
function Address_to_Pointer is new
Unchecked_Conversion (System.Address, pthread_attr_t_ptr);
type pthread_mutexattr_t_ptr is access pthread_mutexattr_t;
function Address_to_Pointer is new
Unchecked_Conversion (System.Address, pthread_mutexattr_t_ptr);
type pthread_mutex_t_ptr is access pthread_mutex_t;
function Address_to_Pointer is new
Unchecked_Conversion (System.Address, pthread_mutex_t_ptr);
type pthread_condattr_t_ptr is access pthread_condattr_t;
function Address_to_Pointer is new
Unchecked_Conversion (System.Address, pthread_condattr_t_ptr);
type pthread_cond_t_ptr is access pthread_cond_t;
function Address_to_Pointer is new
Unchecked_Conversion (System.Address, pthread_cond_t_ptr);
type pthread_key_t_ptr is access pthread_key_t;
function Address_to_Pointer is new
Unchecked_Conversion (System.Address, pthread_key_t_ptr);
type Address_Pointer is access System.Address;
function Address_to_Pointer is new
Unchecked_Conversion (System.Address, Address_Pointer);
type timespec_ptr is access POSIX_Timers.timespec;
function Address_to_Pointer is new
Unchecked_Conversion (System.Address, timespec_ptr);
type Integer_Ptr is access Integer;
function Address_to_Pointer is new
Unchecked_Conversion (System.Address, Integer_Ptr);
-----------------------
-- pthread_attr_init --
-----------------------
procedure pthread_attr_init
(attributes : out pthread_attr_t;
result : out Return_Code)
is
function pthread_attr_init_base
(attr : pthread_attr_t_ptr)
return Return_Code;
pragma Import (C, pthread_attr_init_base, "pthread_attr_init");
begin
result :=
pthread_attr_init_base (Address_to_Pointer (attributes'Address));
end pthread_attr_init;
-------------------------------
-- pthread_attr_setstacksize --
-------------------------------
procedure pthread_attr_setstacksize
(attr : in out pthread_attr_t;
stacksize : size_t;
result : out Return_Code)
is
function pthread_attr_setstacksize_base
(attr : pthread_attr_t_ptr;
stacksize : size_t)
return Return_Code;
pragma Import
(C, pthread_attr_setstacksize_base, "pthread_attr_setstacksize");
begin
result :=
pthread_attr_setstacksize_base
(Address_to_Pointer (attr'Address), stacksize);
end pthread_attr_setstacksize;
---------------------------------
-- pthread_attr_setdetachstate --
---------------------------------
procedure pthread_attr_setdetachstate
(attr : in out pthread_attr_t;
detachstate : Integer;
result : out Return_Code)
is
function pthread_attr_setdetachstate_base
(attr : pthread_attr_t_ptr;
detachstate : Integer_Ptr)
return Return_Code;
pragma Import
(C, pthread_attr_setdetachstate_base, "pthread_attr_setdetachstate");
begin
Result :=
pthread_attr_setdetachstate_base (
Address_to_Pointer (attr'Address),
Address_to_Pointer (detachstate'Address));
end pthread_attr_setdetachstate;
--------------------
-- pthread_create --
--------------------
procedure pthread_create
(thread : out pthread_t;
attributes : pthread_attr_t;
start_routine : System.Address;
arg : System.Address;
result : out Return_Code)
is
function pthread_create_base
(thread : pthread_t_ptr;
attr : pthread_attr_t_ptr;
start_routine : System.Address; arg : System.Address)
return Return_Code;
pragma Import (C, pthread_create_base, "pthread_create");
begin
result :=
pthread_create_base (Address_to_Pointer (thread'Address),
Address_to_Pointer (attributes'Address), start_routine, arg);
end pthread_create;
------------------
-- pthread_init --
------------------
-- This procedure provides a hook into Pthreads initialization that allows
-- the addition of initializations specific to the Ada Pthreads interface
procedure pthread_init is
procedure pthread_init_base;
pragma Import (C, pthread_init_base, "pthread_init");
begin
pthread_init_base;
end pthread_init;
--------------------
-- pthread_detach --
--------------------
procedure pthread_detach
(thread : in out pthread_t;
result : out Return_Code)
is
function pthread_detach_base (thread : pthread_t_ptr) return Return_Code;
pragma Import (C, pthread_detach_base, "pthread_detach");
begin
result := pthread_detach_base (Address_to_Pointer (thread'Address));
end pthread_detach;
----------------------------
-- pthread_mutexattr_init --
----------------------------
procedure pthread_mutexattr_init